package com.lyu.xiaolvshu.auth.sms;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teautil.models.RuntimeOptions;
import com.lyu.framework.common.util.JsonUtils;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AliyunSmsHelper {

    @Resource
    private Client client;

    public boolean sendMessage(String signName, String phone, String templateCode, String templateParam) {
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setSignName(signName)
                .setPhoneNumbers(phone)
                .setTemplateCode(templateCode)
                .setTemplateParam(templateParam);

        RuntimeOptions runtimeOptions = new RuntimeOptions();
        try {
            log.info("==> 开始短信发送, phone: {}, signName: {}, templateCode: {}, templateParam: {}", phone, signName, templateCode, templateParam);
            // 实际没有调用发送方法
            SendSmsResponse sendSmsResponse = new SendSmsResponse();
            //sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtimeOptions);
            log.info("==> 短信发送成功, response: {}", JsonUtils.toJsonString(sendSmsResponse));
            return true;
        } catch (Exception e) {
            log.error("==>发送短信失败:", e);
            return false;
        }
    }
}
